//创建一个新目录
export function CreateNewDir(url, dirName) {
	//url值可支持相对路径URL、本地路径URL
	return new Promise((resolver, reject) => {
		plus.io.resolveLocalFileSystemURL(url, function(entry) {
			entry.getDirectory(dirName, {
				create: true,
				exclusive: false
			}, function(dir) {
				resolver(true)
			}, function(error) {
				reject(error.message)
				// uni.showToast({
				// 	title: dirName + '目录创建失败:' + error.message,
				// 	duration: 2000,
				// 	icon: 'none'
				// });
			});
		}, function(e) {
			reject(error.message)
			// uni.showToast({
			// 	title: '获取目录失败:' + e.message,
			// 	duration: 2000,
			// 	icon: 'none'
			// });
		});
	})
}

export function getFileList(url) {
    return new Promise(resolve => { 
        plus.io.resolveLocalFileSystemURL(
            url,
            function(entry) {
                var directoryReader = entry.createReader(); //获取读取目录对象
                directoryReader.readEntries(
                    function(entries) {
                        resolve(entries)
                    },
                    function(err) {
                        console.log("访问目录失败");
                    });
            },
            function(err) {
                console.log("访问指定目录失败:" + err.message);
            });
    })
}

export function getVideoInfo(url) {
	return new Promise(resolve => {
		uni.getVideoInfo({
			src: url,
			success(res) {
				resolve(res)
			}
		})
	})
} 